home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-taspda.adb < prev    next >
Text File  |  1996-01-30  |  5KB  |  144 lines

  1. -----------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --            S Y S T E M . T A S K _ S P E C I F I C _ D A T A             --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.6 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with Unchecked_Conversion;
  27. with Unchecked_Deallocation;
  28.  
  29. with System.Tasking_Soft_Links; use System.Tasking_Soft_Links;
  30.  
  31. --  This package has to be elaborated after the secondary stack if this
  32. --  package is present. We can't put a pragma elaborate otherwise we would
  33. --  require this package to be always present. So we must rely on the
  34. --  default alphabetical ordering of the binder.
  35.  
  36. package body System.Task_Specific_Data is
  37.  
  38.    type TSD is record
  39.       Jmpbuf_Address : Address := Null_Address;
  40.       GNAT_Exception : Address := Null_Address;
  41.       Sec_Stack_Addr : Address := Null_Address;
  42.    end record;
  43.  
  44.    --  ??? changed the next access type into a general access type to avoid a
  45.    --  lurking visibility problem.
  46.  
  47.    type TSD_Ptr is access all TSD;
  48.  
  49.    function From_Address is new
  50.      Unchecked_Conversion (Address, TSD_Ptr);
  51.  
  52.    function To_Address is new
  53.      Unchecked_Conversion (TSD_Ptr, Address);
  54.  
  55.    ------------------------
  56.    -- Get_Jmpbuf_Address --
  57.    ------------------------
  58.  
  59.    function Get_Jmpbuf_Address return  Address is
  60.    begin
  61.       return From_Address (Get_TSD_Address (True)).Jmpbuf_Address;
  62.    end Get_Jmpbuf_Address;
  63.  
  64.    ------------------------
  65.    -- Set_Jmpbuf_Address --
  66.    ------------------------
  67.  
  68.    procedure Set_Jmpbuf_Address (Addr : Address) is
  69.    begin
  70.       From_Address (Get_TSD_Address (True)).Jmpbuf_Address := Addr;
  71.    end Set_Jmpbuf_Address;
  72.  
  73.    ------------------------
  74.    -- Get_GNAT_Exception --
  75.    ------------------------
  76.  
  77.    function Get_GNAT_Exception return  Address is
  78.    begin
  79.       return From_Address (Get_TSD_Address (True)).GNAT_Exception;
  80.    end Get_GNAT_Exception;
  81.  
  82.    ------------------------
  83.    -- Set_GNAT_Exception --
  84.    ------------------------
  85.  
  86.    procedure Set_GNAT_Exception (Addr : Address) is
  87.    begin
  88.       From_Address (Get_TSD_Address (True)).GNAT_Exception := Addr;
  89.    end Set_GNAT_Exception;
  90.  
  91.    ------------------------
  92.    -- Get_Sec_Stack_Addr --
  93.    ------------------------
  94.  
  95.    function Get_Sec_Stack_Addr return  Address is
  96.    begin
  97.       return From_Address (Get_TSD_Address (True)).Sec_Stack_Addr;
  98.    end Get_Sec_Stack_Addr;
  99.  
  100.    ------------------------
  101.    -- Set_Sec_Stack_Addr --
  102.    ------------------------
  103.  
  104.    procedure Set_Sec_Stack_Addr (Addr : Address) is
  105.    begin
  106.       From_Address (Get_TSD_Address (True)).Sec_Stack_Addr := Addr;
  107.    end Set_Sec_Stack_Addr;
  108.  
  109.    ----------------
  110.    -- Create_TSD --
  111.    ----------------
  112.  
  113.    function Create_TSD return Address is
  114.       New_TSD : constant TSD_Ptr := new TSD;
  115.  
  116.    begin
  117.       System.Tasking_Soft_Links.SS_Init (New_TSD.Sec_Stack_Addr, 10*1024);
  118.       --  Allocate 10K secondary stack
  119.  
  120.       return To_Address (New_TSD);
  121.    end Create_TSD;
  122.  
  123.    -----------------
  124.    -- Destroy_TSD --
  125.    -----------------
  126.  
  127.    procedure Destroy_TSD (TSD_Addr : Address) is
  128.       Old_TSD : TSD_Ptr := From_Address (TSD_Addr);
  129.  
  130.       procedure Free is new
  131.         Unchecked_Deallocation (TSD, TSD_Ptr);
  132.  
  133.    begin
  134.       System.Tasking_Soft_Links.SS_Free (Old_TSD.Sec_Stack_Addr);
  135.       Free (Old_TSD);
  136.    end Destroy_TSD;
  137.  
  138. begin
  139.    --  Intialize the TSD for the non-tasking case
  140.  
  141.    Non_Tasking_TSD := Create_TSD;
  142.  
  143. end System.Task_Specific_Data;
  144.